//
//  SGUserManager.m
//  SemiGroup
//
//  Created by 陈无忌 on 12/9/15.
//  Copyright © 2015 陈无忌. All rights reserved.
//

#import "SGUserManager.h"

static SGUserManager *userManager = nil;

@implementation SGUserManager

+ (id)sharedInstance{
    if (!userManager) {
        userManager = [[SGUserManager alloc] init];
    }
    return userManager;
}

+ (void)destory{
    userManager = nil;
}

#pragma mark - Private method

- (id)init{
    if (userManager) {
        return userManager;
    }
    self = [super init];
    if (self) {
        //do something when init
    }
    return self;
}

#pragma mark - Public method

- (void)saveLoginUsername:(NSString *)username Password:(NSString *)password LoginType:(NSInteger)loginType{
    NSUserDefaults *userdefaults = [NSUserDefaults standardUserDefaults];
    [userdefaults setObject:username forKey:USERNAME];
    [userdefaults setObject:password forKey:PASSWORD];
    [userdefaults setBool:YES forKey:AUTOLOGIN];
}

- (void)cancalAutoLogin{
    NSUserDefaults *userdefaults = [NSUserDefaults standardUserDefaults];
    [userdefaults setBool:NO forKey:AUTOLOGIN];
}

- (BOOL)isNeedToJumpLogin{
    if (![[SGUserManager sharedInstance] isLogin] && ![[NSUserDefaults standardUserDefaults] boolForKey:AUTOLOGIN]) {
        //用户未登录 且没有自动登录
        return YES;
    }else{
        return NO;
    }
}


@end
